//
//  GVMessageProductView.m
//  GmallVIP
//
//  Created by yemeihua on 15/9/11.
//  Copyright (c) 2015年 yemeihua. All rights reserved.
//

#import "GVMessageProductView.h"

@implementation GVMessageProductView

- (instancetype)init
{
    if(self = [super init])
    {
        _productImageView = [[UIImageView alloc] init];
        _productImageView.contentMode = UIViewContentModeScaleAspectFill;
        _productImageView.layer.masksToBounds = YES;
        [self addSubview:_productImageView];
        
        [_productImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.and.height.equalTo(@([[self class] width]));
            make.top.equalTo(@0);
            make.centerX.equalTo(self);
        }];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:16.0];
        [self addSubview:_titleLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_productImageView.mas_bottom).offset(10);
            make.centerX.equalTo(_productImageView);
            make.width.equalTo(_productImageView);
        }];
        
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = [UIColor redColor];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
        _priceLabel.font = [UIFont systemFontOfSize:16.0];
        [self addSubview:_priceLabel];
        
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(10);
            make.centerX.equalTo(_productImageView);
            make.width.equalTo(_productImageView);
        }];
        
        _detailLabel = [[UILabel alloc] init];
        _detailLabel.textColor = [UIColor lightGrayColor];
        _detailLabel.font = [UIFont systemFontOfSize:10.0];
        _detailLabel.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:_detailLabel];
        
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_priceLabel.mas_bottom).offset(10);
            make.centerX.equalTo(_productImageView);
            make.width.equalTo(_productImageView);
        }];
        
        _seeButton = [[UIButton alloc] init];
        _seeButton.backgroundColor = [UIColor blackColor];
        _seeButton.layer.cornerRadius = 4.0;
        _seeButton.layer.masksToBounds = YES;
        _seeButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_seeButton setTitle:@"详情" forState:UIControlStateNormal];
        [self addSubview:_seeButton];
        
        [_seeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@([[self class] width] * 0.44));
            make.height.equalTo(@32);
            make.left.equalTo(@0);
            make.top.equalTo(_detailLabel.mas_bottom).offset(10);
        }];
        
        _buyButton = [[UIButton alloc] init];
        _buyButton.backgroundColor = [UIColor yc_colorWithUInt:0x00d200];
        _buyButton.layer.cornerRadius = 4.0;
        _buyButton.layer.masksToBounds = YES;
        _buyButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_buyButton setTitle:@"购买" forState:UIControlStateNormal];
        [self addSubview:_buyButton];
        
        [_buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@([[self class] width] * 0.44));
            make.height.equalTo(@32);
            make.right.equalTo(@0);
            make.top.equalTo(_detailLabel.mas_bottom).offset(10);
        }];
        
    }
    return self;
}

+ (CGFloat)width
{
    static CGFloat width = 170.0;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        width = kScreenWidth * 0.53;
    });
    return width;
}

@end
